/*
 * Copyright © 2020-present zmzhou-star. All Rights Reserved.
 */

package com.zjh.admin.websocket.config;

import com.zjh.admin.websocket.handle.DocumentWebSocketHandler;
import com.zjh.admin.websocket.handle.GlobalWebSocketHandler;
import com.zjh.admin.websocket.inteceptor.CustomHandshakeInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import javax.annotation.Resource;


@Configuration
@EnableWebSocket
public class GlobleWebSocketConfig implements WebSocketConfigurer {
	@Resource
	private GlobalWebSocketHandler globalWebSocketHandler;

	@Resource
	private DocumentWebSocketHandler documentWebSocketHandler;

	@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
		//socket通道
		//指定处理器和路径
		webSocketHandlerRegistry.addHandler(globalWebSocketHandler, "/global-connect")
				.addInterceptors(new CustomHandshakeInterceptor())
				.setAllowedOrigins("*");

		// 纯文本协同编辑
		webSocketHandlerRegistry.addHandler(documentWebSocketHandler, "/documentEdit")
				.addInterceptors(new CustomHandshakeInterceptor())
				.setAllowedOrigins("*");
	}
}
